//2009/08/08 00:57:18
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

class Pool
{
public:
    int rackMoves(vector <int> triangle)
    {
		s[0] = "X00X8X0X0XX0X00";
		s[1] = "0XX080X0X00X0XX";
        int cost1 = 0;
        int cost2 = 0;
        for (int i=0; i<triangle.size(); i++)
        {
            if (triangle[i] > 0 && triangle[i] < 8)
            {
                if (s[0][i] != '0') cost1 ++;
                if (s[1][i] != '0') cost2 ++;
            }
            else if (triangle[i] > 8 && triangle[i] < 16)
            {
                if (s[0][i] != 'X') cost1 ++;
                if (s[1][i] != 'X') cost2 ++;
            }
            else
            {
                if (s[0][i] != '8') cost1 ++;
                if (s[1][i] != '8') cost2 ++;
            }
        }
		return (min(cost1, cost2) + 1) / 2;
    }
private:
    string s[2];
};
